package utils

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type ResponseType struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data"`
}

func HandleResponse(ctx *gin.Context, code int, msg string, data any) {
	ctx.JSON(http.StatusOK, gin.H{
		"code": code,
		"msg":  msg,
		"data": data,
	})
}

// HandleSuccessResponse 成功的返回
func HandleSuccessResponse(ctx *gin.Context, msg string, data any) {
	HandleResponse(ctx, 0, msg, data)
	ctx.Abort()
}

// HandleFailResponse 失败的返回
func HandleFailResponse(ctx *gin.Context, msg string, data any) {
	HandleResponse(ctx, 1, msg, data)
	ctx.Abort()
}
